package top.jle.wx.proxy.api.templateMsg;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.jle.wx.proxy.api.ResponseBack;
import top.jle.wx.proxy.domain.templateMsg.MiniprogramMessageOption;
import top.jle.wx.proxy.domain.templateMsg.ToMiniprogramMessageOption;
import top.jle.wx.proxy.domain.templateMsg.ToURLMessageOption;
import top.jle.wx.proxy.facade.TemplateMsgFacade;

import java.util.Set;

@RestController
@RequestMapping("/template")
@Tag(name = "模板消息API")
public class TemplateMsgAPI {

    @Autowired
    private TemplateMsgFacade templateMsgFacade;

    @Operation(summary = "发送模板消息（跳转URL模式）",description = "返回msgid用于事件处理")
    @PostMapping("/send_url")
    public ResponseBack<String> sendURL(@RequestBody ToURLMessageOption messageOption){
        String msgId = templateMsgFacade.sendTemplateMsg(messageOption);
        return ResponseBack.success(msgId);
    }
    @Operation(summary = "批量发送模板消息（跳转URL模式）",description = "返回queueId用于获取msgid列表 有效期1天")
    @PostMapping("/send_url/batch")
    public ResponseBack<String> sendURLBatch(@Parameter(description="OPENID列表") @RequestParam Set<String> openids, @RequestBody ToURLMessageOption messageOption){
        String queueId = templateMsgFacade.sendTemplateMsg_batch(openids,messageOption);
        return ResponseBack.success(queueId);
    }

    @Operation(summary = "发送模板消息（跳转小程序模式）",description = "返回msgid用于事件处理")
    @PostMapping("/send_mini")
    public ResponseBack<String> sendMini(@RequestBody ToMiniprogramMessageOption messageOption){
        String msgId = templateMsgFacade.sendTemplateMsg(messageOption);
        return ResponseBack.success(msgId);
    }

    @Operation(summary = "批量发送模板消息（跳转小程序模式）",description = "返回queueId用于获取msgid列表 有效期1天")
    @PostMapping("/send_mini/batch")
    public ResponseBack<String> sendMiniBatch(@Parameter(description="OPENID列表") @RequestParam Set<String> openids,@RequestBody ToMiniprogramMessageOption messageOption){
        String queueId = templateMsgFacade.sendTemplateMsg_batch(openids,messageOption);
        return ResponseBack.success(queueId);
    }

    @Operation(summary = "发送小程序模板消息")
    @PostMapping("/send_nativemp")
    public ResponseBack<Boolean> sendToMiniprogram(@RequestBody MiniprogramMessageOption miniprogramMessageOption){
        templateMsgFacade.sendTemplateMsgToMiniprogram(miniprogramMessageOption);
        return ResponseBack.success(true);
    }
    @Operation(summary = "根据QueueID获取MsgId列表")
    @GetMapping("/msgIds/{queueId}")
    public ResponseBack<Set<String>> getMsgIds(@Parameter(description="队列ID") @PathVariable String queueId){
       Set<String> msgIds =  templateMsgFacade.getMsgIds(queueId);
       return ResponseBack.success(msgIds);
    }
}
